
/*

 * Copyright (C) 2021 Huawei Device Co., Ltd.

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */
package me.aartikov.alligator.commands;

import me.aartikov.alligator.util.Log;
import me.aartikov.alligator.NavigationContext;
import me.aartikov.alligator.animations.AnimationData;
import me.aartikov.alligator.exceptions.MissingScreenSwitcherException;
import me.aartikov.alligator.exceptions.NavigationException;
import me.aartikov.alligator.screenswitchers.ScreenSwitcher;
import me.aartikov.alligator.Screen;

import java.util.List;

public class ReduceCommand implements Command {

    private List<Screen> mScreen;

    private AnimationData mAnimationData;

    /**
     * 构造方法
     * @param screen 需要还原的Screen组
     * @param animationData  动画
     */
    public ReduceCommand(List<Screen> screen, AnimationData animationData) {
        mScreen = screen;
        mAnimationData = animationData;
    }

    /**
     *  进行还原操作
     * @param navigationContext navigation context that can be used for a command implementation
     * @return 是否完成
     * @throws NavigationException 异常
     */
    @Override
    public boolean execute( NavigationContext navigationContext) throws NavigationException {
        ScreenSwitcher screenSwitcher = navigationContext.getScreenSwitcher();
        Log.i("SwitchToCommand.execute([navigationContext]):27   "+screenSwitcher);
        if (screenSwitcher == null) {
            throw new MissingScreenSwitcherException("ScreenSwitcher is not set.");
        }
        screenSwitcher.reduce(mScreen, navigationContext.getScreenSwitchingListener(), mAnimationData);
        return true;
    }
}
